/**
 * @Date: Mar 3, 2010 11:57:33 AM
 */
package com.philip.journal.home.dao;

import java.util.List;
import java.util.Map;

import com.philip.journal.core.Messages;
import com.philip.journal.core.dao.BaseDAOImpl;
import com.philip.journal.core.exception.JournalException;
import com.philip.journal.home.bean.Branch;

/**
 * @author cry30
 */
public class BranchDAOImpl extends BaseDAOImpl<Branch> implements BranchDAO {

    @Override
    public List<Branch> readAllByParent(final long parentId) {
        final List<Branch> retval = super.readAllByParent(Branch.ATTR_PARENT, Branch.ATTR_BRANCH_ID,
                Long.valueOf(parentId));
        return retval;
    }

    @Override
    public Branch readByProperty(final Map<String, Object> param) {
        return super.readObject(param);
    }

    @Override
    public void deleteAll(final List<Branch> listObj)
    {
        if (listObj == null) {
            throw JournalException.wrapperException(new IllegalArgumentException(Messages.Error.IAE_NULL));
        }
        for (final Branch branch : listObj) {
            if (branch == null) {
                throw JournalException.wrapperException(new IllegalArgumentException(Messages.Error.IAE_NULL));
            }
        }
        super.deleteAll0(listObj);
    }

    @Override
    public List<Branch> readAllByProperty(final String property, final Object value) {
        return super.readAll0(property, value);
    }

    @Override
    public Branch read(final long branchId) {
        try {
            return super.read(branchId);
        } catch (final JournalException e) {
            getLogger().debug(e.getMessage(), e);
            return super.readObject(Branch.ATTR_BRANCH_ID, branchId);
        }
    }

    @Override
    public Branch readByName(final String branchName, final long parentId) {
        return super.readObjectByParent(Branch.ATTR_PARENT, Branch.ATTR_BRANCH_ID, Long.valueOf(parentId),
                Branch.ATTR_NAME,
                branchName);
    }
}